<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <title>Document</title>
</head>
<body>
    <h1>首页</h1>
    <button class="btn-getuserinfo"  onclick="getUserInfo()">获取用户信息</button>
    <button class="btn-logout"  onclick="logout()">退出登入</button>
</body>
<script>
    var userinfo = {}
    
    function getUserInfo(){
        axios.get('/userinfo').then(({data})=>{
            let btn = document.querySelector('.btn-getuserinfo')
            console.log(data)
            if(data.code){
                btn.innerHTML = data.errorMsg
            }else{
                btn.innerHTML = '欢迎'+data.nickname
                userinfo = data
            }
        }).catch(err=>{
            console.log(err)
        })
    }
    function logout(){
        window.location.href='/logout'
    }
</script>
</html>